<?php
/*
 * @Author: lokei
 * @Date: 2022-09-18 13:16:51
 * @LastEditors: lokei
 * @LastEditTime: 2022-10-30 21:08:00
 * @Description: 
 */
namespace App\Http\Controllers\Store\Type;

use App\Common\Tools\ResultTool;
use App\Http\Controllers\Controller;
use App\Models\Platform\Type\TypeModel;
use App\Models\Store\StoreModel;
use Illuminate\Http\Request;

class TypeController extends Controller {
    public function ofStore(Request $request) {
        $store = StoreModel::where('id', '=', $request->input('store_id'))->first();
        $res = ResultTool::success();
        $type_ids = explode('|', $store->types);
        $items = TypeModel::whereIn('id', $type_ids)->get();
        $res['data']['items'] = $items;
        return $res;
    }

    public function set(Request $request) {
        $store = StoreModel::where('id', '=', $request->input('id'))->first();
        $store->types = $request->input('types');
        $store->save();
        return ResultTool::success();
    }
}